import math

from seaman.core import JsonUtil

from passcheck.model import PassCheckParams

class PaResult:
    bending_radius: float
    m: float
    n: float
    double_l: float
    l: float
    radius1: float


# 测井仪器在通过裸眼段时几何分析
def get_passibility_analysis(params: PassCheckParams) -> PaResult:
    result = PaResult()
    # 套管的曲率半径R1
    # radius1 = get_curvature_radius(a, b)
    radius1 = 200
    # 裸眼段的曲率半径R0
    # radius0 = get_curvature_radius(a, b)
    # 最小挠曲半径
    bending_radius = params.elastic_modulus * params.cable_diameter * 0.5 / params.allowable_stress
    # 根据坐标点以及管柱相切的条件将公式代入下述三个公式
    result.bending_radius = bending_radius
    m = params.casing_diameter * 0.5 - params.instrument_diameter * 0.5 + bending_radius
    result.m = m
    n = params.casing_diameter * 0.5 - bending_radius - params.cable_diameter * 0.5
    result.n = n
    double_l = 4 * math.pow(n + radius1, 2) - 4 * math.pow(radius1 - m, 2)
    result.double_l = double_l
    l = 2 * math.pow((math.pow(n+radius1, 2) - math.pow(radius1-m, 2)), 1/2)
    result.l = l
    radius1 = 0.125 * (math.pow(l, 2) - 4 * (math.pow(n, 2) - math.pow(m, 2))) / (n + m)
    result.radius1 = radius1
    return result

if __name__ == '__main__':
    data = PassCheckParams()
    # 电缆的弹性模量
    data.elastic_modulus = 210
    # 测井工具的外径
    data.instrument_diameter = 0.09
    # 电缆的许用应力
    data.allowable_stress = 160
    # 电缆的外径
    data.cable_diameter = 0.0132
    # 套管的直径
    data.casing_diameter = 0.14
    # 裸眼段的直径
    data.naked_diameter = 0.2

    pa_result = get_passibility_analysis(data)
    print(JsonUtil.obj2str(pa_result))